<template>
  <!-- 放置一个图标 -->
  <div>
    <svg-icon :icon-class="isFullscreen ? 'exit-fullscreen': 'fullscreen' " class="fullscreen" @click="toggleScreen" />
  </div>
</template>

<script>
import screenfull from 'screenfull'
export default {
  name: 'ScreenFull',
  data() {
    return {
      isFullscreen: false // 控制是否为全屏的变量
    }
  },
  mounted() {
    screenfull.on('change', () => {
      this.isFullscreen = screenfull.isFullscreen
    })
  },

  methods: {
    // 点击全屏
    toggleScreen() {
      // 调用  插件提供的 toggle 方法，实现切换全屏
      screenfull.toggle()

      this.isFullscreen = true
    }
  }
}
</script>

<style lang="scss" scoped>
.fullscreen {
  width: 20px;
  height: 20px;
  color: #fff;
  cursor: pointer;
}
</style>
